package com.atguigu.registration.common.utils;

/**
 * @Author: Jiang Yizhi
 * @Date: 2022/5/6 9:59 PM
 */

import com.atguigu.registration.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/** 获取当前用户信息的工具类 */
public class AuthContextHolder {

    /** 获取当前用户的id */
    public static Long getUserId(HttpServletRequest request) {
        /** 从header里获取token */
        String token = request.getHeader("token");
        /** jwt从token里面获取userid */
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    /** 获取当前用户名 */
    public static String getUserName(HttpServletRequest request) {
        String token = request.getHeader("token");
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
